home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / zendisk2.zip / LST14-12.ASM < prev    next >
Assembly Source File  |  1990-02-15  |  2KB  |  89 lines

  1. ;
  2. ; *** Listing 14-12 ***
  3. ;
  4. ; Demonstrates scanning a table with REPNZ SCASW in
  5. ; order to generate an index to be used with a jump table.
  6. ;
  7.     jmp    Skip
  8. ;
  9. ; Branches to the routine corresponding to the key code in
  10. ; AX. Simply returns if no match is found.
  11. ;
  12. ; Input:
  13. ;    AX = 16-bit key code, as returned by the BIOS
  14. ;
  15. ; Output: none
  16. ;
  17. ; Registers altered: CX, DI, ES
  18. ;
  19. ; Direction flag cleared
  20. ;
  21. ; Table of 16-bit key codes this routine handles.
  22. ;
  23. KeyLookUpTable    label    word
  24.     dw    1e41h, 3042h, 2e43h, 2044h    ;A-D
  25.     dw    1245h, 2146h, 2247h, 2347h    ;E-H
  26.     dw    1749h, 244ah, 254bh, 264ch    ;I-L
  27.     dw    324dh, 314eh, 184fh, 1950h    ;M-P
  28.     dw    1051h, 1352h, 1f53h, 1454h    ;Q-T
  29.     dw    1655h, 2f56h, 1157h, 2d58h    ;U-X
  30.     dw    1559h, 2c5ah            ;Y-Z
  31. KEY_LOOK_UP_TABLE_LENGTH_IN_WORDS equ (($-KeyLookUpTable)/2)
  32. ;
  33. ; Table of addresses to which to jump when the corresponding
  34. ; key codes in KeyLookUpTable are found. All the entries
  35. ; point to the same routine, since this is for illustrative
  36. ; purposes only, but they could easily be changed to point
  37. ; to any label in the code segment.
  38. ;
  39. KeyJumpTable    label    word
  40.     dw    HandleA_Z, HandleA_Z, HandleA_Z, HandleA_Z
  41.     dw    HandleA_Z, HandleA_Z, HandleA_Z, HandleA_Z
  42.     dw    HandleA_Z, HandleA_Z, HandleA_Z, HandleA_Z
  43.     dw    HandleA_Z, HandleA_Z, HandleA_Z, HandleA_Z
  44.     dw    HandleA_Z, HandleA_Z, HandleA_Z, HandleA_Z
  45.     dw    HandleA_Z, HandleA_Z, HandleA_Z, HandleA_Z
  46.     dw    HandleA_Z, HandleA_Z
  47. ;
  48. VectorOnKey    proc    near
  49.     mov    di,cs
  50.     mov    es,di
  51.     mov    di,offset KeyLookUpTable
  52.             ;point ES:DI to the table of keys
  53.             ; we handle, which is in the same
  54.             ; code segment as this routine
  55.     mov    cx,KEY_LOOK_UP_TABLE_LENGTH_IN_WORDS
  56.             ;# of words to scan
  57.     cld
  58.     repnz    scasw    ;look up the key
  59.     jnz    VectorOnKeyDone    ;it's not in the table, so
  60.                 ; we're done
  61.     jmp    cs:[KeyJumpTable+di-2-offset KeyLookUpTable]
  62.             ;jump to the routine for this key
  63.             ; Note that:
  64.             ;   DI-2-offset KeyLookUpTable
  65.             ; is the offset in KeyLookUpTable of
  66.             ; the key we found, with the -2
  67.             ; needed to compensate for the
  68.             ; 2-byte (1-word) overrun of SCASW
  69. HandleA_Z:
  70. VectorOnKeyDone:
  71.     ret
  72. VectorOnKey    endp
  73. ;
  74. Skip:
  75.     call    ZTimerOn
  76.     mov    ax,1e41h
  77.     call    VectorOnKey    ;look up 'A'
  78.     mov    ax,1749h
  79.     call    VectorOnKey    ;look up 'I'
  80.     mov    ax,1f53h
  81.     call    VectorOnKey    ;look up 'S'
  82.     mov    ax,2c5ah
  83.     call    VectorOnKey    ;look up 'Z'
  84.     mov    ax,0
  85.     call    VectorOnKey    ;finally, look up a key
  86.                 ; code that's not in the
  87.                 ; table
  88.     call    ZTimerOff
  89.